package com.ws.user.role.service.impl;

import com.ws.common.easyui.util.Page;
import com.github.pagehelper.PageHelper;
import com.ws.user.role.dao.RolePermissionMapper;
import com.ws.user.role.entity.RolePermission;
import com.ws.user.role.service.IRolePermissionService;
import com.ws.common.base.service.Impl.BaseServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class RolePermissionServiceImpl extends BaseServiceImpl<RolePermission> implements IRolePermissionService{

	@Autowired
	RolePermissionMapper rolePermissionMapper;

	@Override
	public List<RolePermission> list(RolePermission params) {
		return rolePermissionMapper.list(params);
	}

	@Override
	public List<RolePermission> list(RolePermission params, Page page) {
		PageHelper.startPage(page.getPage(),page.getRows(),page.getSortOrder());
		return rolePermissionMapper.list(params);
	}

	@Override
	public Integer save(RolePermission rolePermission) {
		return this.insertOrUpdate(rolePermission);
	}

	@Override
	public List<String> listPermissionIdByRoleId(String roleId) {
		Map<String,Object> map=new HashMap<>();
		map.put("roleId",roleId);
		List<RolePermission> rolePermissions=this.listByMap(map);

		List<String> results=new ArrayList<>();
		for (RolePermission rolePermission : rolePermissions){
			results.add(rolePermission.getPermissionId());
		}
		return results;
	}

	@Override
	public Integer deleteByRoleId(String roleId) {
		return rolePermissionMapper.deleteByRoleId(roleId);
	}
}
